<template>
  <!-- 商品橱窗对话框 -->
  <div class="add">
    <el-dialog
      title="添加商品"
      :visible.sync="isAdd"
      width="40%"
      :before-close="cancel">
      <div class="add-content">
        <div class="label">商品类型</div>
        <div class="select">
          <el-select v-model="value" @change="$forceUpdate();" placeholder="请选择">
            <el-option label="SAAS商城商品" value="saas"></el-option>
            <el-option label="外部商品" value="external"></el-option>
          </el-select>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="success" @click="submit">确认</el-button>
        <el-button @click="cancel">取消</el-button>
      </span>
    </el-dialog>

    <!--添加SAAS商城商品-->
    <add-product :isAddProduct="isAddProduct" @close="closeShopWindow" :id="id"></add-product>
    <!--添加外部商品-->
    <edit :isEdit="isExternal" @close="closeEdit" :id="id"></edit>
  </div>
</template>

<script>
import PageMixin from '@/framework/mixins/pageMixin'
import AddProduct from "@/framework/components/dialog/live/list/addProduct"
import Edit from "@/framework/components/dialog/goods/list/edit"

export default {
  name:'add',
  mixins: [
    PageMixin,
  ],
  components:{ AddProduct,Edit },
  props: {
    isAdd:{
      type: Boolean,
      default: () => {
        return false
      }
    },
    id:{
      type: String,
      default: () => {
        return ''
      }
    }
  },
  data() {
    return {
      value:'',//绑定内容
      isAddProduct: false,//添加SAAS商城商品
      isExternal: false,//添加外部商品
      isUpdate: false,//是否添加了商品
    }
  },
  watch:{
    // idList(val){
    //   //获取传过来的id
    //   this.id = val.length>0 ? this.idList[0] : ''
    //   console.log(this.id)
    //   if(this.id){ //编辑
    //
    //   }
    // }
  },
  methods: {
    //关闭添加SAAS商品弹框
    closeShopWindow(){
      this.isAddProduct = false
    },
    //关闭添加外部商品弹框
    closeEdit(isUpdate){
      // console.log("是否修改：",isUpdate)
      this.isExternal = false
      this.isUpdate = isUpdate
    },
    //提交
    submit(){
      if(this.value == 'saas'){
        this.isAddProduct = true
      }else if(this.value == 'external'){
        this.isExternal = true
      }
    },
    //取消
    cancel(){
      this.value = ''
      this.$emit('close',this.isUpdate);
    },
  }
}
</script>

<style lang="less" scoped>
.add-content{
  display: flex;
  align-content: center;

  .label{
    padding: 5px 0;
  }

  .select{
    margin-left: 10px;
  }
}
</style>
